# app/models/channel.py
from app import db
from datetime import datetime
from sqlalchemy import Enum

class Channel(db.Model):
    __tablename__ = 'channels'

    channel_id = db.Column(db.String(36), primary_key=True)
    server_id = db.Column(db.String(36), db.ForeignKey('servers.server_id'), nullable=False)
    name = db.Column(db.String(100), nullable=False)
    type = db.Column(Enum('text', 'voice', name='channel_types'), nullable=False)
    position = db.Column(db.Integer, default=0)
    created_at = db.Column(db.DateTime, default=datetime.utcnow)
    descripe = db.Column(db.String(255))

    server = db.relationship('Server', back_populates='channels')
    permissions = db.relationship('ChannelPermission', back_populates='channel')
    messages = db.relationship('Message', back_populates='channel')

    def __repr__(self):
        return f'<Channel {self.name} ({self.server.name})>'